<?php
namespace app\appletsapi\controller;

use app\common\service\SwooleClient;
use http\Client;
use think\Controller;

class Test extends Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @route('test/dochat')
     * 客服列表
     */
    public function test(){
//        $data = [
//            '111',
//        ];
//        $client = new SwooleClient();
//        $client->connect('127.0.0.1',8083,1);
//        $client->send("hello world\n");
//        $client->close();
        $client= new \Swoole\Client(SWOOLE_SOCK_TCP);//默认同步tcp客户端，添加参数SWOOLE_SOCK_ASYNC为异步

        $ret = $client->connect('127.0.0.1',8083,1);

        if(empty($ret)){

            echo 'error!connect to swoole_server failed';

        } else {

            $client->send('blue');
            var_dump($client->send('blue and red'));
//            var_dump(234);
//            var_dump($client->recv());
        }
    }


}